# -*- coding: utf-8 -*-
"""
@Time    : 2024/8/27 11:13 
@Author  : ZhangShenao 
@File    : 1.OpenAI原生API支持多模态.py 
@Desc    : 使用OpenAI原生API支持多模态,实现图片识别
"""
import os

import dotenv
from openai import OpenAI

dotenv.load_dotenv()

client = OpenAI(base_url=os.getenv("OPENAI_API_BASE"))

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "这张图片展示的是哪座城市？"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://img1.baidu.com/it/u=644490943,1781886584&fm=253&fmt=auto&app=138&f=JPEG"
                    },
                },
            ],
        }
    ],
    max_tokens=300,
)

print(response.choices[0])
